package com.yunchang.springboot.config.MWS;

import com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersAsyncClient;
import com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersClient;

import java.util.concurrent.ExecutorService;

public class MarketplaceWebServiceOrdersConfig {
    private static String ACCESS_KEY = "AKIAI7ISC53ENUSBNB2A";
    private static String SECRET_KEY = "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";
    private static final String APP_NAME = "AmazonJavascriptScratchpad";
    private static final String APP_VERSION = "1.0";
    //private static  String SERVICE_URL = "https://mws.amazonservices.com";
    private static MarketplaceWebServiceOrdersAsyncClient client = null;

    public MarketplaceWebServiceOrdersConfig() {
    }

    public static MarketplaceWebServiceOrdersClient getClient(String accessKey,String secretKey,String serviceURL) {
        return getAsyncClient(accessKey,secretKey,serviceURL);
    }

    public static synchronized MarketplaceWebServiceOrdersAsyncClient getAsyncClient(String accessKey,String secretKey,String serviceURL) {
        //if (client == null || !(ACCESS_KEY.equals(accessKey) && SECRET_KEY.equals(secretKey))) {
            com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersConfig config = new com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersConfig();
            config.setServiceURL(serviceURL);
            client = new MarketplaceWebServiceOrdersAsyncClient(accessKey, secretKey, APP_NAME, APP_VERSION, config, (ExecutorService)null);
            //ACCESS_KEY = accessKey;
            //SECRET_KEY = secretKey;
        //}

        return client;
    }
}
